<template>
    <div>
        <el-container>
            <el-header class='homeHeader'>
                <div class='title'>博客-管理平台</div>
                <el-dropdown class='userInfo' @command="commandHandler">
                      <span class="el-dropdown-link">
                        <i><img :src="getImageSrc(user.userface)"></i>{{user.name}}
                      </span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item command="userinfo">个人中心</el-dropdown-item>
                        <el-dropdown-item command="setting">设置</el-dropdown-item>
                        <el-dropdown-item command="logout" divided>注销登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-header>
            <el-container style="height: 90vh;">
                <el-aside width="200px" class="el-menu">
                    <el-menu  router unique-opened>
                        <el-submenu :index="''+index" v-for="(item,index) in routes" v-if="!item.hidden" :key="index">
                            <template slot="title">
                                <i style="color: #409eff;margin-right: 10px" :class="item.iconCls"></i>
                                <span>{{item.name}}</span>
                            </template>
                            <el-menu-item :index="child.path" v-for="(child,indexj) in item.children" :key="indexj">{{child.name}}</el-menu-item>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-main>
                    <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path !='/home'">
                        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                        <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
                    </el-breadcrumb>
                    <div class="homeWelcome" v-if="this.$router.currentRoute.path =='/home'">
                        欢迎 welcome！！！
                    </div>
                    <router-view class="homeRouterView"/>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
    export default {
        name: "home",
        data(){
            return{
                user:JSON.parse(window.sessionStorage.getItem("user"))
            }
        },
        computed:{
            routes(){
                return this.$store.state.routes;
            }
        },
        methods:{
           /* menuClick(index){
              // console.log(index);
              // console.log(indexPath);
                this.$router.push(index);
            },*/
            getImageSrc(headUrl){
                if(headUrl.startsWith('http')){
                    return headUrl;
                }
                return "http://47.95.17.160:81/"+headUrl;
            },
            commandHandler(cmd){
                if(cmd == 'logout') {
                    this.$confirm('此操作将注销登录, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.postRequest("/logout");
                        window.sessionStorage.removeItem("user");
                        window.sessionStorage.removeItem("token");
                        this.$router.replace("/");
                        this.$store.commit('initRoutes', []);
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消操作'
                        });
                    });
                }
            }
        }
    }
</script>

<style>
    .homeHeader{
        background-color: #409eff;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0px 15px;
        box-sizing: border-box;
    }
    .homeHeader .title{
        font-size: 30px;
        font-family: 华文行楷;
        color: #ffffff;
    }
    .homeWelcome{
        text-align: center;
        font-size: 50px;
        font-family: 华文行楷;
        color: #409eff;
        padding-top: 50px;
    }
    .homeRouterView{
        margin-top: 10px;
    }
    /*对一些浏览器的支持*/
    .el-menu {
        overflow: -moz-scrollbars-none;  /* Firefox */
        -ms-overflow-style: none;        /* Internet Explorer 10+ */
        scrollbar-width: none;           /* Firefox */
        /*display: block;
        position: relative;
        overflow-y: scroll;*/
        background-color: #f1f4fa !important;
    }
    /*找到滚动条在谁身上 设置下面的属性*/
    .el-menu::-webkit-scrollbar {
        display: none;  /* Chrome, Safari, Opera */
    }
    .el-dropdown-link {
        cursor: pointer;
        font-size: 16px;
        display: flex;
        align-items: center;
        font-family: 华文行楷;
        color: #ffffff;
    }
    .el-dropdown-link img{
        width: 40px;
        height: 40px;
        border-radius: 24px;
        margin-right: 8px;
    }
</style>